#!/usr/bin/env python

from optparse import OptionParser
from os import makedirs, sep
from os.path import abspath, dirname, isdir, join

from util import (
    getResourcesDirectory,
    getTemplatesDirectory,
    writeTemplate
)

def main():
    parser = OptionParser("usage: %prog [options] binDir dataDir")
    parser.add_option("-d", "--desktop-file", action="store",
                      default=join(getResourcesDirectory(),
                                   "synthclone.desktop"),
                      dest="desktopFile", help="Desktop file destination")
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.error("incorrect number of required arguments")

    desktopFile = options.desktopFile
    desktopDir = dirname(desktopFile)
    if not isdir(desktopDir):
        makedirs(desktopDir)
    data = {
        "binDir": abspath(args[0]),
        "dataDir": abspath(args[1])
    }
    writeTemplate(desktopFile,
                  join(getTemplatesDirectory(), "synthclone.desktop"), data)

if __name__ == "__main__":
    main()
